package com.sky.controller.admin;

import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐相关接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

//    @PutMapping
//    public Result upda

@GetMapping("/page")
@ApiOperation(value = "套餐分页查询")
     public  Result<PageResult> findMealQueryPage( SetmealPageQueryDTO setmealPageQueryDTO){
    log.info("套餐分页查询的信息为，{}",setmealPageQueryDTO);
    PageResult mealQueryPage = setmealService.findMealQueryPage(setmealPageQueryDTO);
    return Result.success(mealQueryPage);
}


    @PostMapping("/status/{status}")
    @ApiOperation(value = "套餐起售停售")
    @CacheEvict(value = "userSetmeal",allEntries = true)
    public  Result startOrStop(@PathVariable Integer status,Long id){
        log.info("套餐的启停信息为，{},{}",status,id);
        setmealService.startOrStop(status,id);
        return Result.success();
    }

    @PostMapping
    @ApiOperation(value = "套餐新增")
    public  Result add(@RequestBody SetmealDTO setmealDTO){
        log.info("套餐的新增信息为，{}",setmealDTO);
        setmealService.add(setmealDTO);
        return Result.success();
    }

    @DeleteMapping
    @ApiOperation(value = "批量删除套餐")
    public  Result add(Long[] ids){
        log.info("要删除的套餐id信息为，{}",ids);
        setmealService.delete(ids);
        return Result.success();
    }


    @GetMapping("/{id}")
    @ApiOperation(value = "通过id寻找套餐")
    public  Result<SetmealVO> findByid(@PathVariable Long id){
        log.info("要查找的套餐id信息为，{}",id);
        SetmealVO byid = setmealService.findByid(id);
        return Result.success(byid);
    }

    @PutMapping
    @ApiOperation(value = "修改套餐")
    @CacheEvict(value = "userSetmeal",key = "#setmealDTO.categoryId")
    public  Result update(@RequestBody SetmealDTO setmealDTO){
        log.info("套餐的新增信息为，{}",setmealDTO);
        setmealService.update(setmealDTO);
        return Result.success();
    }







}
